<?php
namespace Admin\Controller;
use Think\Controller;
class VideoController extends Controller{
	public function videoList(){
		$video = M('video');
		$show = $video->select();
		$this->assign('show',$show);
		$this->display();
	}

	function video(){
		if(IS_POST){
			$file = $_FILES['name'];
			// $title = I('post.video_name');
			$data = app_upload_video($file);
			// var_dump($data);die;
			$form['video_path'] = $data['0'];
			// var_dump($form);
			// var_dump($data);die;
			oss_upload($data);
			$url = get_url($data);
			$video = M('video');
			$form['video_url'] = $url;
			$form['video_ten_id'] = 1;
			// var_dump($form);die;
			if($video->add($form)){
				$this->success();
			}else{
				$this->error();
			}
		}else{
			$this->display();	
		}
	}
	/*****************删除在线存储文件  文件名前面不可以添加/ 运行时需要删除****************/
	function delete(){
		$id = I('get.video_id');
		$video = M('video');
		$data = $video->where('video_id='.$id)->select();
		// var_dump($data);die;
		$list = ltrim($data['0']['video_path'],'/');
		oss_delete_object($list);
		 if($video->where('video_id='.$id)->delete()){
		 	$this->success('成功');
		 }else{
		 	$this->error('失败');
		 }
		// if(!empty($data)){
		// 	echo json_encode(1);
		// }else{
		// 	echo json_encode(2);
		// }
	}
}